using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Entity
{
    public class TblNewsletterSubscriberExtended : TblNewsletterSubscriber
    {
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static int GetAllTblNewsletterSubscriberCountByGroup(int groupId)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@GroupId", SqlDbType.Int, 0, ParameterDirection.Input, groupId);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBL_NEWSLETTER_SUBSCRIBER_GET_ALL_TBL_NEWSLETTER_SUBSCRIBER_COUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static List<TblNewsletterSubscriber> GetAllTblNewsletterSubscriberByGroup(string SortBy, int CurrentPageIndex, int PageSize, int SubscriberGroupId)
        {
            //Validate Input
            if (SortBy == "")
                SortBy = "NewsletterSubscriberId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, SortBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, CurrentPageIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, PageSize);
            AddParameterToSqlCmd(sqlCmd, "@groupId", SqlDbType.Int, 0, ParameterDirection.Input, SubscriberGroupId);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SPR_TBL_NEWSLETTER_SUBSCRIBER_GET_ALL_TBL_NEWSLETTER_SUBSCRIBER_BY_GROUP);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblNewsletterSubscriberCollectionFromReader);
            List<TblNewsletterSubscriber> objCollection = ((List<TblNewsletterSubscriber>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        internal const string SPR_TBL_NEWSLETTER_SUBSCRIBER_GET_ALL_TBL_NEWSLETTER_SUBSCRIBER_BY_GROUP = "spr_TblNewsletterSubscriber_GetAllTblNewsletterSubscriberByGroup";  
        internal const string SPR_TBL_NEWSLETTER_SUBSCRIBER_GET_ALL_TBL_NEWSLETTER_SUBSCRIBER_COUNT = "spr_TblNewsletterSubscriber_GetAllTblNewsletterSubscriberCount";  
    }
}
